/* Archive Extractor
 * Copyright 2008-2009 Matthew Hoops
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $URL: http://archive-extractor.googlecode.com/svn/trunk/ms_comp.cpp $
 * $Id: ms_comp.cpp 2 2009-03-23 01:29:43Z clone2727 $
 *
 */

#include "ms_comp.h"

MicrosoftCompressedArchive::MicrosoftCompressedArchive() : StandardArchive() {
}

std::vector<const char*> MicrosoftCompressedArchive::getArchiveExtensions() {
	std::vector<const char*> exList;
	exList.push_back("??_");
	return exList;
}

int MicrosoftCompressedArchive::detect(FILE* file) {
	uint32 tag = readUint32BE(file);
	if (tag == 'SZDD') {
		if (readUint32LE(file) != 0x3327f088)
			return 0;
		_version = 5;
		return 100;
	} else if (tag == 'KWAJ') {
		_version = 6;
		return 100;
	}
	return 0;
}

bool MicrosoftCompressedArchive::extractFiles(FILE* file) {
	if (_version == 6) {
		printf ("Microsoft Compressed Archives (6.22) 'KWAJ' are not supported at this time.\n");
		return false;
	}
	
	fseek(file, 8, SEEK_SET); // We already checked the first 8 bytes
	readByte(file); // Reserved
	char lastChar = (char)readByte(file); // Since it ends with _, let's get the final letter. However, sometimes this is not provided :(
	uint32 uncompressedSize = readUint32LE(file);
	
	// TODO: Generate output file name
	// TODO: Extract LZSS compressed data	
	
	return false;
}
